<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: Retreval::Runner</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/retreval/runner_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/retreval/runner.rb">lib/retreval/runner.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-begin_calculations">#begin_calculations</a></li>
					
					<li><a href="#method-i-load_gold_standard">#load_gold_standard</a></li>
					
					<li><a href="#method-i-load_query_result_set">#load_query_result_set</a></li>
					
					<li><a href="#method-i-run">#run</a></li>
					
					<li><a href="#method-i-write_to_yaml_file">#write_to_yaml_file</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
				
					<li class="file"><a href="../TODO.html">TODO</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../Retreval.html">Retreval</a></li>
				
					<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
				
					<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
				
					<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
				
					<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
				
					<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
				
					<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
				
					<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
				
					<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
				
					<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
				
					<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
				
					<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
				
					<li><a href="../Retreval/User.html">Retreval::User</a></li>
				
					<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
				
					<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">Retreval::Runner</h1>

		<div id="description">
			<p>
A simple class that performs the task of running this library when called
from the commandline
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(args)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Invokes a new <a href="Runner.html">Runner</a> object by loading the
options from the commandline
</p>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 16</span>
16:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
17:       <span class="ruby-ivar">@options</span> = <span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">args</span>)
18:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="begin-calculations-method" class="method-detail ">
				<a name="method-i-begin_calculations"></a>

				<div class="method-heading">
				
					<span class="method-name">begin_calculations</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Performs the default calculations and writes their output to the file
specified
</p>
					

					
					<div class="method-source-code"
						id="begin-calculations-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 67</span>
67:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">begin_calculations</span>
68:       <span class="ruby-ivar">@statistics</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
69:       <span class="ruby-ivar">@average_precision</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
70:       
71:       <span class="ruby-ivar">@query_result_set</span>.<span class="ruby-identifier">query_results</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">result</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
72:         <span class="ruby-keyword kw">begin</span>
73:           <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;Cleaning up results and removing documents without judgements ... \n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
74:           <span class="ruby-identifier">result</span>.<span class="ruby-identifier">cleanup</span>
75:           
76:           <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Calculating statistics for result #{index+1} of #{@query_result_set.query_results.count} ... &quot;</span>
77:           <span class="ruby-ivar">@statistics</span>[<span class="ruby-identifier">result</span>.<span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span>] = <span class="ruby-identifier">result</span>.<span class="ruby-identifier">statistics</span>
78:           <span class="ruby-ivar">@average_precision</span>[<span class="ruby-identifier">result</span>.<span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span>] = <span class="ruby-identifier">result</span>.<span class="ruby-identifier">average_precision</span>
79:           <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;Done.\n&quot;</span>
80:           
81:           <span class="ruby-identifier">result</span>.<span class="ruby-identifier">print_ranked_table</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>          
82:           
83:           <span class="ruby-identifier">write_to_yaml_file</span> <span class="ruby-value">:data</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@statistics</span>, <span class="ruby-value">:filename</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;statistics.yml&quot;</span>
84:           <span class="ruby-identifier">write_to_yaml_file</span> <span class="ruby-value">:data</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@average_precision</span>, <span class="ruby-value">:filename</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;avg_precision.yml&quot;</span>
85:           
86:         <span class="ruby-comment cmt"># rescue Exception =&gt; e</span>
87:         <span class="ruby-comment cmt">#  raise &quot;Error while calculating results: #{e}&quot;</span>
88:         <span class="ruby-keyword kw">end</span>
89:       <span class="ruby-keyword kw">end</span>
90:       
91:       <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;Finished calculating all results. Exiting.\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
92:       <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;The mean average precision was #{@query_result_set.mean_average_precision}\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
93:       <span class="ruby-identifier">exit</span>
94:       
95:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="load-gold-standard-method" class="method-detail ">
				<a name="method-i-load_gold_standard"></a>

				<div class="method-heading">
				
					<span class="method-name">load_gold_standard</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Takes the passed options for a <a href="GoldStandard.html">GoldStandard</a>
file and loads it according to the format specified
</p>
					

					
					<div class="method-source-code"
						id="load-gold-standard-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 21</span>
21:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_gold_standard</span>
22:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">gold_standard_file</span>.<span class="ruby-identifier">nil?</span>
23:         
24:           
25:         <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Loading gold standard file '#{@options.gold_standard_file}' ... &quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
26:         <span class="ruby-ivar">@gold_standard</span> = <span class="ruby-constant">GoldStandard</span>.<span class="ruby-identifier">new</span>
27:         <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">format</span>
28:         <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;yaml&quot;</span>
29:           <span class="ruby-ivar">@gold_standard</span>.<span class="ruby-identifier">load_from_yaml_file</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">gold_standard_file</span>
30:         <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;plain&quot;</span>
31:           <span class="ruby-ivar">@gold_standard</span>.<span class="ruby-identifier">load_from_plaintext_file</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">gold_standard_file</span>
32:         <span class="ruby-keyword kw">else</span>
33:           <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;I don't understand the format '#{@options.format}'&quot;</span>
34:         <span class="ruby-keyword kw">end</span>
35:         
36:         <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;done\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
37:         <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Gold standard loaded from #{@options.gold_standard_file} contains:
38:           - #{@gold_standard.queries.count} queries, 
39:           - #{@gold_standard.documents.count} documents,
40:           - #{@gold_standard.judgements.count} judgements, made by
41:           - #{@gold_standard.users.count} users\n\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>        
42:       <span class="ruby-keyword kw">end</span>
43:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="load-query-result-set-method" class="method-detail ">
				<a name="method-i-load_query_result_set"></a>

				<div class="method-heading">
				
					<span class="method-name">load_query_result_set</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Takes the passed options for a <a
href="QueryResultSet.html">QueryResultSet</a> file and loads it according
to the format specified
</p>
					

					
					<div class="method-source-code"
						id="load-query-result-set-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_query_result_set</span>
47:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">query_result_set_file</span>.<span class="ruby-identifier">nil?</span>
48:           
49:         <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Loading query result set from file '#{@options.query_result_set_file}' ... &quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
50:         <span class="ruby-ivar">@query_result_set</span> = <span class="ruby-constant">QueryResultSet</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:gold_standard</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@gold_standard</span>
51:         <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">format</span>
52:         <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;yaml&quot;</span>
53:           <span class="ruby-ivar">@query_result_set</span>.<span class="ruby-identifier">load_from_yaml_file</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">query_result_set_file</span>
54:         <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;plain&quot;</span>
55:           <span class="ruby-ivar">@query_result_set</span>.<span class="ruby-identifier">load_from_yaml_file</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">query_result_set_file</span>
56:         <span class="ruby-keyword kw">else</span>
57:           <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;I don't understand the format '#{@options.format}'&quot;</span>
58:         <span class="ruby-keyword kw">end</span>
59:         
60:         <span class="ruby-identifier">print</span> <span class="ruby-value str">&quot;done\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
61:         <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Query results loaded from #{@options.query_result_set_file} contain:
62:           - #{@query_result_set.query_results.count} query results\n\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
63:       <span class="ruby-keyword kw">end</span>
64:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="run-method" class="method-detail ">
				<a name="method-i-run"></a>

				<div class="method-heading">
				
					<span class="method-name">run</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Called when the script is executed from the command line
</p>
					

					
					<div class="method-source-code"
						id="run-source">
<pre>
     <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 113</span>
113:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>
114:       
115:       <span class="ruby-identifier">load_gold_standard</span>
116:       <span class="ruby-identifier">load_query_result_set</span>
117:       <span class="ruby-identifier">begin_calculations</span>
118:       
119:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="write-to-yaml-file-method" class="method-detail ">
				<a name="method-i-write_to_yaml_file"></a>

				<div class="method-heading">
				
					<span class="method-name">write_to_yaml_file</span><span
						class="method-args">(args)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Writes an object to a YAML file. Called by:
</p>
<pre>
    write_to_yaml_file :data =&gt; my_data, :filename =&gt; &quot;my_data_file.yml&quot;</pre>
					

					
					<div class="method-source-code"
						id="write-to-yaml-file-source">
<pre>
     <span class="ruby-comment cmt"># File lib/retreval/runner.rb, line 100</span>
100:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write_to_yaml_file</span>(<span class="ruby-identifier">args</span>)
101:       <span class="ruby-identifier">data</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:data</span>]
102:       <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:filename</span>]
103:       
104:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">nil?</span> 
105:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Must pass filename and data in order to write to file!&quot;</span>
106:       <span class="ruby-keyword kw">end</span>
107:       
108:       <span class="ruby-identifier">filename</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">output</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;_&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">filename</span>
109:       <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-value str">&quot;w&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">to_yaml</span> }
110:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

